﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Devider
{
    class Program
    {
        static void Main(string[] args)
        {
            Devide();
            Collect();
        }
        public static void Devide()
        {
            using (FileStream inFile =
    new FileStream("lopez.jpg", FileMode.Open))
            {
                byte[] buf = new byte[5 * 1024];
                using (FileStream outFile1 = new FileStream("out1.bin", FileMode.Create))
                {
                    using (FileStream outFile2 = new FileStream("out2.bin", FileMode.Create))
                    {
                        while (true)
                        {
                            int bytesRead = inFile.Read(buf, 0, buf.Length);
                            if (bytesRead == 0)
                            {
                                break;
                            }
                            outFile1.Write(buf, 0, bytesRead);
                            bytesRead = inFile.Read(buf, 0, buf.Length);
                            if (bytesRead == 0)
                            {
                                break;
                            }
                            outFile2.Write(buf, 0, bytesRead);
                        }
                    }
                }
            }
        }

        public static void Collect()
        {
            using (FileStream inFile1 =
    new FileStream("out1.bin", FileMode.Open))
            using (FileStream inFile2 =
   new FileStream("out2.bin", FileMode.Open))
            using (FileStream outFile =
new FileStream("newLopez.jpg", FileMode.Create))
            {
                byte[] buf = new byte[5 * 1024];

                while (true)
                {
       
                                int bytesRead = inFile1.Read(buf, 0, buf.Length);
                                if (bytesRead == 0)
                                {
                                    break;
                                }
                                outFile.Write(buf, 0, bytesRead);

                                 bytesRead = inFile2.Read(buf, 0, buf.Length);
                                if (bytesRead == 0)
                                {
                                    break;
                                }
                                outFile.Write(buf, 0, bytesRead);    
                    }

            }
        }
    }
}
